/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    int maxdepth=0;
    int maxDepth(TreeNode* root) {
        if(root==nullptr){return 0;}
        else{return depthorder(root);}
    }
    int depthorder(TreeNode* root){
        if(root->left==nullptr && root->right==nullptr){return 1;}
        else if(root->left!=nullptr && root->right!=nullptr){return max(depthorder(root->left),depthorder(root->right))+1;}
        else if(root->left!=nullptr){return depthorder(root->left)+1;}
        else{return depthorder(root->right)+1;}
    }
};